package com.video.server;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;


public class AddKCServer extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		DiskFileItemFactory factory = new DiskFileItemFactory();
		ServletContext context = req.getServletContext();
		String path = context.getRealPath("/");
		factory.setRepository(new File(path));
		factory.setSizeThreshold(1024*1024);
		ServletFileUpload upload = new ServletFileUpload(factory);
		upload.setFileSizeMax(-1);//设置文件大小，-1无上限
		 try {  
	            @SuppressWarnings("unchecked")  
	            List<FileItem> list = upload.parseRequest(req);
	            String va = null;  
	            KcPO kPO = new KcPO();
	            for(FileItem item : list){  
	                if(item.isFormField()){//判断是否是文件流  
	                    va = item.getString("UTF-8");  
	                    System.out.println(va);
	                }else{  
	                    item.write(new File("d:/a.png"));
	                }  
	            }  
	        } catch (Exception e) {  
	              
	            e.printStackTrace();  
	        }  
		
	}

	
}
